/**
 * 饮食模块 API
 */

const request = require('./request');

// 获取指定日期的餐食记录
const getMealsByDate = async (date) => {
  return request.get('/diet/meals', { date });
};

// 获取单个餐食详情
const getMealById = async (id) => {
  return request.get(`/diet/meals/${id}`);
};

// 添加餐食记录
const addMeal = async (data) => {
  return request.post('/diet/meals', data);
};

// 更新餐食记录
const updateMeal = async (id, data) => {
  return request.put(`/diet/meals/${id}`, data);
};

// 删除餐食记录
const deleteMeal = async (id) => {
  return request.delete(`/diet/meals/${id}`);
};

// 搜索食物
const searchFoods = async (query, category) => {
  return request.get('/diet/foods/search', { query, category });
};

// 通过天行API搜索食物营养信息
const searchTianapiFood = async (query, mode = 0, num = 10, page = 1) => {
  return request.get('/diet/foods/tianapi/search', { query, mode, num, page });
};

// 保存天行API返回的食物到数据库
const saveTianapiFood = async (foodData) => {
  return request.post('/diet/foods/tianapi/save', { foodData });
};

// 获取推荐食物
const getRecommendedFood = async () => {
  return request.get('/diet/foods/recommended');
};

// 获取食物分类
const getFoodCategories = async () => {
  return request.get('/diet/foods/categories');
};

// 获取食物详情
const getFoodById = async (id) => {
  return request.get(`/diet/foods/${id}`);
};

// 添加自定义食物
const addCustomFood = async (data) => {
  return request.post('/diet/foods', data);
};

// 获取饮食营养统计
const getNutritionStats = async (startDate, endDate) => {
  return request.get('/diet/stats', { startDate, endDate });
};

// 获取推荐食谱
const getFeaturedRecipes = async (limit = 4) => {
  return request.get('/diet/recipes/featured', { limit });
};

// 获取适合特定健康状况的食谱
const getRecipesBySuitability = async (condition, stage, limit = 10) => {
  return request.get('/diet/recipes/suitable', { condition, stage, limit });
};

// 获取食谱列表（支持分类筛选）
const getRecipes = async (params) => {
  return request.get('/diet/recipes', params);
};

// 搜索食谱
const searchRecipes = async (params) => {
  return request.get('/diet/recipes/search', params);
};

// 通过天行API搜索菜谱
const searchTianapiRecipes = async (query, num = 10, page = 1) => {
  return request.get('/diet/recipes/tianapi/search', { query, num, page });
};

// 保存天行API返回的菜谱到数据库
const saveTianapiRecipe = async (recipeData) => {
  return request.post('/diet/recipes/tianapi/save', { recipeData });
};

// 获取菜谱推荐
const getRecipeRecommendations = async (params) => {
  return request.get('/diet/recipes/recommend', params);
};

// 获取食谱详情
const getRecipeById = async (id) => {
  return request.get(`/diet/recipes/${id}`);
};

// 获取用户的所有餐食记录
const getAllMeals = async () => {
  return request.get('/diet/meals');
};

// 获取食物推荐
const getFoodRecommendations = async () => {
  return request.get('/food/recommend');
};

// 获取食物GI值数据
const getFoodGIList = async () => {
  return request.get('/food/gi');
};

// 获取单个食物的GI值数据
const getFoodGIById = async (id) => {
  return request.get(`/food/gi/${id}`);
};

module.exports = {
  getMealsByDate,
  getMealById,
  addMeal,
  updateMeal,
  deleteMeal,
  searchFoods,
  searchTianapiFood,
  saveTianapiFood,
  getRecommendedFood,
  getFoodCategories,
  getFoodById,
  addCustomFood,
  getNutritionStats,
  getFeaturedRecipes,
  getRecipesBySuitability,
  searchRecipes,
  getRecipeById,
  getRecipes,
  searchTianapiRecipes,
  saveTianapiRecipe,
  getRecipeRecommendations,
  getAllMeals,
  getFoodRecommendations,
  getFoodGIList,
  getFoodGIById
}; 